home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00053_Util- mais manipulacao de strings e acentos.ls < prev    next >
Encoding:
Text File  |  1999-03-19  |  3.6 KB  |  132 lines

  1. -- Inicializacao dos metodos de manipulacao de string
  2. -- Deve ser chamado uma vez antes de utilizar os outros
  3. -- metodos
  4. on utilInicializa
  5.   
  6.   global gAcentos_pc, gAcentos_mac, gConvertido
  7.   -- Lista dos codigos dos acentos no PC
  8.   put [225, 193, 233, 201, 237, 205, 243, 211, 250, 218, 226, 194, ┬¼
  9.        234, 202, 238, 206, 244, 212, 251, 219, 227, 195, 245, 213, ┬¼
  10.        241, 209, 224, 192, 232, 200, 236, 204, 242, 210, 249, 217, ┬¼
  11.        231, 199, 228, 196, 235, 203, 239, 207, 246, 214, 252, 220] ┬¼
  12.       into gAcentos_pc
  13.   -- Acentos Mac
  14.   put [135, 231, 142, 131, 146, 234, 151, 238, 156, 242, 137, 229, ┬¼
  15.        144, 230, 148, 235, 153, 239, 158, 243, 139, 204, 155, 205, ┬¼
  16.        150, 132, 136, 203, 143, 233, 147, 237, 152, 241, 157, 244, ┬¼
  17.        141, 130, 138, 128, 145, 232, 149, 236, 154, 133, 159, 134] ┬¼
  18.       into gAcentos_mac
  19.   put "aaeeiioouuaaeeiioouuaaoonnaaeeiioouuccaaeeiioouu"┬¼
  20.       into gConvertido
  21. end
  22.  
  23. on pcToMac texto
  24.   global gAcentos_pc, gAcentos_mac, gConvertido
  25.   
  26.   set num = the number of chars in texto
  27.   set res = ""
  28.   repeat with i = 1 to num 
  29.     set c = char i of texto
  30.     set tmp = getPos(gAcentos_pc, charToNum(c))
  31.     if tmp <> 0 then set c = NumToChar(getAt(gAcentos_mac,tmp))
  32.     set res = res & c
  33.   end repeat
  34.   
  35.   return res
  36. end
  37.  
  38.  
  39. -- Tira acentos e coloca tudo minusculo
  40. on canoniza pal
  41.   global gAcentos_pc, gAcentos_mac, gConvertido
  42.   
  43.   put "" into res
  44.   put 1 into counter
  45.   put length(pal) into len
  46.   repeat while counter <= len
  47.     put charToNum(char counter of pal) into c
  48.     if (c >= charToNum("A") and c <= charToNum("Z")) then
  49.       put c - charToNum("A") + charToNum("a") into c
  50.     else
  51.       if the platform contains "Win" then 
  52.         put getPos(gAcentos_pc, c) into tmp
  53.       else -- Mac
  54.         put getPos(gAcentos_mac, c) into tmp
  55.       end if
  56.       if tmp <> 0 then 
  57.         put charToNum(char tmp of gConvertido) into c
  58.       end if
  59.     end if
  60.     put numToChar(c) after res
  61.     put counter + 1 into counter
  62.   end repeat
  63.   return res
  64. end
  65.  
  66. -- Verifica se e' letra
  67. on e_letra c
  68.   global gAcentos_pc, gAcentos_mac, gConvertido
  69.   
  70.   if c >= "A" and c <= "Z" then return true
  71.   if c >= "a" and c >= "z" then return true
  72.   
  73.   if the platform contains "Win" then 
  74.     put getPos(gAcentos_pc, charToNum(c)) into tmp
  75.   else -- Mac
  76.     put getPos(gAcentos_mac, charToNum(c)) into tmp
  77.   end if
  78.   if tmp > 0 then return true
  79.   
  80.   return false
  81. end
  82.  
  83. -- Faz italicos para textos que nao tem hipertexto
  84. on fazItalicos textoMember
  85.   set mem = the number of member textoMember
  86.   set texto = the text of member mem
  87.   set c = 1
  88.   set italico = false
  89.   set w = the number of words in texto
  90.   put "Palavras a serem percorridas: " & w
  91.   repeat while c <= w 
  92.     set pal = word c of texto
  93.     if pal contains "{" then
  94.       set italico = true
  95.     end if
  96.     if italico then
  97.       set the fontStyle of word c of member mem to "italic"
  98.     end if
  99.     if pal contains "}" then
  100.       set italico = false
  101.     end if
  102.     set c = c + 1
  103.     if c mod 25 = 0 then
  104.       put ". " & c
  105.     end if
  106.   end repeat
  107. end
  108.  
  109. on fazNegrito textoMember
  110.   set mem = the number of member textoMember
  111.   set texto = the text of member mem
  112.   set c = 1
  113.   set negrito = false
  114.   set w = the number of words in texto
  115.   put "Palavras a serem percorridas: " & w
  116.   repeat while c <= w 
  117.     set pal = word c of texto
  118.     if pal contains "[" then
  119.       set negrito = true
  120.     end if
  121.     if negrito then
  122.       set the fontStyle of word c of member mem to "bolt"
  123.     end if
  124.     if pal contains "]" then
  125.       set negrito = false
  126.     end if
  127.     set c = c + 1
  128.     if c mod 25 = 0 then
  129.       put ". " & c
  130.     end if
  131.   end repeat
  132. end